package com.zhongkun.datahome.service.export.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.zhongkun.datahome.common.constant.Constants;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * @Author: lifengsheng
 * @Date: 2025/5/13 16:26
 * @Desc
 */
public class UrlListConverter implements Converter<List<String>> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return List.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.EMPTY;
    }

    @Override
    public List<String> convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

    @Override
    public WriteCellData<?> convertToExcelData(List<String> urls, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        WriteCellData<Object> cellData = new WriteCellData<>(CellDataTypeEnum.EMPTY);

        if (CollectionUtils.isNotEmpty(urls)) {
            cellData.setStringValue(String.join(Constants.COMMA_SEPARATOR, urls));
        }
        return cellData;
    }
}
